nLab sum type

Contents

Context

Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism =
propositions as types +programs as proofs +relation type theory/category theory

logicset theory (internal logic of)category theorytype theory
propositionsetobjecttype
predicatefamily of setsdisplay morphismdependent type
proofelementgeneralized elementterm/program
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
introduction rule for implicationcounit for hom-tensor adjunctionlambda
elimination rule for implicationunit for hom-tensor adjunctionapplication
cut elimination for implicationone of the zigzag identities for hom-tensor adjunctionbeta reduction
identity elimination for implicationthe other zigzag identity for hom-tensor adjunctioneta conversion
truesingletonterminal object/(-2)-truncated objecth-level 0-type/unit type
falseempty setinitial objectempty type
proposition, truth valuesubsingletonsubterminal object/(-1)-truncated objecth-proposition, mere proposition
logical conjunctioncartesian productproductproduct type
disjunctiondisjoint union (support of)coproduct ((-1)-truncation of)sum type (bracket type of)
implicationfunction set (into subsingleton)internal hom (into subterminal object)function type (into h-proposition)
negationfunction set into empty setinternal hom into initial objectfunction type into empty type
universal quantificationindexed cartesian product (of family of subsingletons)dependent product (of family of subterminal objects)dependent product type (of family of h-propositions)
existential quantificationindexed disjoint union (support of)dependent sum ((-1)-truncation of)dependent sum type (bracket type of)
logical equivalencebijection setobject of isomorphismsequivalence type
support setsupport object/(-1)-truncationpropositional truncation/bracket type
n-image of morphism into terminal object/n-truncationn-truncation modality
equalitydiagonal function/diagonal subset/diagonal relationpath space objectidentity type/path type
completely presented setsetdiscrete object/0-truncated objecth-level 2-type/set/h-set
setset with equivalence relationinternal 0-groupoidBishop set/setoid with its pseudo-equivalence relation an actual equivalence relation
equivalence class/quotient setquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
-0-truncated higher colimitquotient inductive type
coinductionlimitcoinductive type
presettype without identity types
set of truth valuessubobject classifiertype of propositions
domain of discourseuniverseobject classifiertype universe
modalityclosure operator, (idempotent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels

semantics

Contents

Idea

In type theory a sum type of two types AA and BB (really: coproduct) is the type whose terms are either terms a:Aa\colon A or terms b:Bb\colon B.

In a model of the type theory in categorical semantics this is a distributive coproduct. In set theory, it is a disjoint union.

Definition

Like all type constructors in type theory, to characterize sum types we must specify how to build them, how to construct elements of them, how to use such elements, and the computation rules.

The way to build sum types is easy:

A:TypeB:TypeA+B:Type \frac{A\colon Type \qquad B\colon Type}{A+B \colon Type}

As a positive type

Sum types are most naturally presented as positive types, so that the constructor rules are primary. These say that we can obtain an element of A+BA+B from an element of AA, or from an element of BB.

a:Ainl(a):A+Bb:Binr(b):A+B \frac{a\colon A}{inl(a)\colon A+B} \qquad \frac{b\colon B}{inr(b)\colon A+B}

The eliminator is derived from these: it says that in order to use an element of A+BA+B, it suffices to specify what should be done for the two ways in which that element could have been constructed.

p:A+Bx:Ac A:Cy:Bc B:Cmatch(p,x.c A,y.c B):C \frac{p\colon A+B \qquad x\colon A\vdash c_A\colon C \qquad y\colon B \vdash c_B\colon C}{match(p, x.c_A, y.c_B) \colon C}

The terms c Ac_A and c Bc_B can have free variables xx and yy respectively, but those variables become bound in the matchmatch expression. In dependent type theory, we must generalize the eliminator to allow CC to depend on A+BA+B.

The beta reduction rules for a constructor followed by an eliminator:

match(inl(a),x.c A,y.c B) βc A[a/x] match(inr(b),x.c A,y.c B) βc B[b/y] \begin{aligned} match(inl(a), x.c_A, y.c_B) &\to_\beta c_A[a/x]\\ match(inr(b), x.c_A, y.c_B) &\to_\beta c_B[b/y] \end{aligned}

The eta reduction rule for the opposite composite says that for any term c:Cc\colon C in the context of p:A+Bp\colon A+B,

match(p,x.c[inl(x)/z],y.c[inr(y)/z]) ηc[p/z].match(p, x.c[inl(x)/z], y.c[inr(y)/z]) \to_\eta c[p/z].

This says that if we unpack a term of type A+BA+B, but only use the resulting term of type AA or BB by way of packing them back into A+BA+B, then we might as well not have unpacked them to begin with. Note that choosing CA+BC\coloneqq A+B and czc \coloneqq z, we obtain a simpler form of η\eta-conversion:

match(p,x.inl(x),y.inr(y)) ηp.match(p, x.inl(x), y.inr(y)) \to_\eta p.

The positive presentation of sum types can be regarded as a particular sort of inductive type. In Coq syntax:

Inductive sum (A B:Type) : Type :=
| inl : A -> sum A B
| inr : B -> sum A B.

Coq implements the beta reduction rule, but not the eta (although eta equivalence is provable for the inductively defined identity types, using the dependent eliminator mentioned above).

As a negative type

It is possible to present sum types as negative types as well, but only if we allow sequents with multiple conclusions. This is common in sequent calculus presentations of classical logic, but not as common in type theory and almost unheard of in dependent type theory.

The two definitions are provably equivalent, but only using the contraction rule and the weakening rule. Thus, in linear logic they become distinct; the positive sum type is “plus” ABA\oplus B and the negative one is “par” ABA \parr B.

With typal computation and uniqueness rules

Assuming that identification types, function types and dependent product types exist in the type theory, the sum type of types AA and BB is the inductive type generated by a function from AA to A+BA + B and a function from BB to A+BA + B:

Formation rules for sum types:

ΓAtypeΓBtypeΓA+Btype\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma \vdash A + B \; \mathrm{type}}

Introduction rules for sum types:

ΓAtypeΓBtypeΓin A:AA+BΓAtypeΓBtypeΓin B:BA+B\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma \vdash \mathrm{in}_A:A \to A + B} \qquad \frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type}}{\Gamma \vdash \mathrm{in}_B:B \to A + B}

Elimination rules for sum types:

ΓAtypeΓBtypeΓ,x:A+BC(x)typeΓc in A: x:AC(in A(x))Γc in B: y:BC(in B(y))Γz:A+BΓind A+B C(c in A,c in B,z):C(y)\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A + B \vdash C(x) \; \mathrm{type} \quad \Gamma \vdash c_{\mathrm{in}_A}:\prod_{x:A} C(\mathrm{in}_A(x)) \quad \Gamma \vdash c_{\mathrm{in}_B}:\prod_{y:B} C(\mathrm{in}_B(y)) \quad \Gamma \vdash z:A + B}{\Gamma \vdash \mathrm{ind}_{A + B}^C(c_{\mathrm{in}_A}, c_{\mathrm{in}_B}, z):C(y)}

Computation rules for sum types:

ΓAtypeΓBtypeΓ,x:A+BC(x)typeΓc in A: x:AC(in A(x))Γc in B: y:BC(in B(y))Γa:AΓβ A+B in A(c in A,c in B,a):Id C(in A(a))(ind A+B C(c in A,c in B,in A(a)),c(a))\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A + B \vdash C(x) \; \mathrm{type} \quad \Gamma \vdash c_{\mathrm{in}_A}:\prod_{x:A} C(\mathrm{in}_A(x)) \quad \Gamma \vdash c_{\mathrm{in}_B}:\prod_{y:B} C(\mathrm{in}_B(y)) \quad \Gamma \vdash a:A}{\Gamma \vdash \beta_{A + B}^{\mathrm{in}_A}(c_{\mathrm{in}_A}, c_{\mathrm{in}_B}, a):\mathrm{Id}_{C(\mathrm{in}_A(a))}(\mathrm{ind}_{A + B}^C(c_{\mathrm{in}_A}, c_{\mathrm{in}_B}, \mathrm{in}_A(a)), c(a))}
ΓAtypeΓBtypeΓ,x:A+BC(x)typeΓc in A: x:AC(in A(x))Γc in B: y:BC(in B(y))Γb:BΓβ A+B in B(c in A,c in B,b):Id C(in B(b))(ind A+B C(c in A,c in B,in B(b)),c(b))\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A + B \vdash C(x) \; \mathrm{type} \quad \Gamma \vdash c_{\mathrm{in}_A}:\prod_{x:A} C(\mathrm{in}_A(x)) \quad \Gamma \vdash c_{\mathrm{in}_B}:\prod_{y:B} C(\mathrm{in}_B(y)) \quad \Gamma \vdash b:B}{\Gamma \vdash \beta_{A + B}^{\mathrm{in}_B}(c_{\mathrm{in}_A}, c_{\mathrm{in}_B}, b):\mathrm{Id}_{C(\mathrm{in}_B(b))}(\mathrm{ind}_{A + B}^C(c_{\mathrm{in}_A}, c_{\mathrm{in}_B}, \mathrm{in}_B(b)), c(b))}

Uniqueness rules for sum types:

ΓAtypeΓBtypeΓ,x:A+BC(x)typeΓc: x:A+BC(x)Γz:A+BΓη A+B(c,z):Id C(z)(ind A+B C(λx:A.c(in A(x)),λy:B.c(in B(y)),z),c(z))\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A + B \vdash C(x) \; \mathrm{type} \quad \Gamma \vdash c:\prod_{x:A + B} C(x) \quad \Gamma \vdash z:A + B}{\Gamma \vdash \eta_{A + B}(c, z):\mathrm{Id}_{C(z)}(\mathrm{ind}_{A + B}^C(\lambda x:A.c(\mathrm{in}_A(x)), \lambda y:B.c(\mathrm{in}_B(y)), z), c(z))}

The elimination, computation, and uniqueness rules for the sum type of AA and BB state that the sum type of AA and BB satisfy the dependent universal property of the sum type of AA and BB. If the dependent type theory also has dependent sum types and product types, allowing one to define the uniqueness quantifier, the dependent universal property of the sum type of of AA and BB could be simplified to the following rule:

ΓAtypeΓBtypeΓ,x:A+BC(x)typeΓc in A: x:AC(in A(x))Γc in B: y:BC(in B(y))Γup A+B C(c in A,c in B):!c: x:A+BC(x).( a:AId C(in A(a))(c(in A(a)),c in A(a)))×( b:BId C(in B(b))(c(in B(b)),c in B(b)))\frac{\Gamma \vdash A \; \mathrm{type} \quad \Gamma \vdash B \; \mathrm{type} \quad \Gamma, x:A + B \vdash C(x) \; \mathrm{type} \quad \Gamma \vdash c_{\mathrm{in}_A}:\prod_{x:A} C(\mathrm{in}_A(x)) \quad \Gamma \vdash c_{\mathrm{in}_B}:\prod_{y:B} C(\mathrm{in}_B(y))}{\Gamma \vdash \mathrm{up}_{A + B}^C(c_{\mathrm{in}_A}, c_{\mathrm{in}_B}):\exists!c:\prod_{x:A + B} C(x).\left(\prod_{a:A} \mathrm{Id}_{C(\mathrm{in}_A(a))}(c(\mathrm{in}_A(a)), c_{\mathrm{in}_A}(a))\right) \times \left(\prod_{b:B} \mathrm{Id}_{C(\mathrm{in}_B(b))}(c(\mathrm{in}_B(b)), c_{\mathrm{in}_B}(b))\right)}

In terms of dependent sum types and booleans

The sum type can be defined in terms of the boolean domain and the dependent sum type. Given types AA and BB, the sum type A+BA + B is defined as

A+B x:Bool((x= Bool1)A)×((x= Bool0)B)A + B \coloneqq \sum_{x:\mathrm{Bool}} ((x =_\mathrm{Bool} 1) \to A) \times ((x =_\mathrm{Bool} 0) \to B)

Properties

Descent and large elimination

The descent for the sum type A+BA + B states that given any type families x:AC(x)x:A \vdash C(x) and y:BD(y)y:B \vdash D(y) one can construct a type family z:A+BdescFam A+B C,D(z)z:A + B \vdash \mathrm{descFam}_{A + B}^{C, D}(z) with families of equivalences of types

x:AdescEquiv A+B C:descFam A+B C,D(inl(x))C(x)x:A \vdash \mathrm{descEquiv}_{A + B}^C:\mathrm{descFam}_{A + B}^{C, D}(\mathrm{inl}(x)) \simeq C(x)
y:BdescEquiv A+B D:descFam A+B C,D(inr(y))D(y)y:B \vdash \mathrm{descEquiv}_{A + B}^D:\mathrm{descFam}_{A + B}^{C, D}(\mathrm{inr}(y)) \simeq D(y)

Large elimination for sum types strengthens the equivalences of types in descent to judgmental equality of types

x:AdescFam A+B C,D(inl(x))C(x)typex:A \vdash \mathrm{descFam}_{A + B}^{C, D}(\mathrm{inl}(x)) \equiv C(x) \; \mathrm{type}
y:BdescFam A+B C,D(inr(y))D(y)typey:B \vdash \mathrm{descFam}_{A + B}^{C, D}(\mathrm{inr}(y)) \equiv D(y) \; \mathrm{type}

References

A textbook account in the context of programming languages is in section 12 of

For sum types in homotopy type theory, see:

Last revised on February 27, 2024 at 21:37:37. See the history of this page for a list of all contributions to it.